﻿using Microsoft.AspNetCore.Mvc;
using SMARTHOTEL.Cients;
using SMARTHOTEL.Customers;
using SMARTHOTEL.StayRecords;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;
using Yitter.IdGenerator;

namespace SMARTHOTEL.Reservationses
{
    [ApiExplorerSettings(GroupName = "v2")]
    public class ReservationsService : ApplicationService
    {
        IRepository<Reservations> repository;

        public ReservationsService(IRepository<Reservations> repository)
        {
            this.repository = repository;
        }
        /// <summary>
        /// 添加订房订单
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("InsertReservations")]
        public async Task<ResultDto<bool>> InsertReservations(InsertReservationsDto dto)
        {
            try
            {
                dto.OrderNumber = YitIdHelper.NextId().ToString();
     
                Reservations entity = ObjectMapper.Map<InsertReservationsDto, Reservations>(dto);       
                await repository.InsertAsync(entity);
                return new ResultDto<bool> { Data = true, Code = StatusCode.Success, Message = "添加成功" };
            }
            catch (Exception ex)
            {

                return new ResultDto<bool> { Data = false, Code = StatusCode.Faield, Message = "添加失败" + ex.Message };
            }
        }
        /// <summary>
        /// 查询    订房订单
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetReservations")]
        public async Task<ResultDto<List<ReservationsDto>>> GetReservations()
        {
            var list = await repository.GetListAsync();
            return new ResultDto<List<ReservationsDto>>
            {
                Data=ObjectMapper.Map<List<Reservations>,List<ReservationsDto>>(list),
                Code = StatusCode.Success,
                Message="查询成功"
            };
        }
    }
}
